﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KCMS.DataAcsess.Interfaces;
using KCMS.DataAcsess.Entitys;
using System.Data.Linq;
namespace KCMS.DataAcsess.Engine
{
    public class ProductImageManager : IProductImageManager
    {
        protected DataClassesDataContext db = new DataBaseConnect().DataBase;
        private DataManager<ProductImageEntity> dm=new DataManager<ProductImageEntity>();
        public ProductImageEntity getById(Guid id)
        {
            return (from t in db.GetTable<ProductImageEntity>()
                    where t.Id.Equals(id)
                    select t).SingleOrDefault();
        }
        public IEnumerable<ProductImageEntity> getAll()
        {
            //return (from t in db.GetTable<ProductImageEntity>()
            //            select t).ToList();
            return dm.getAll();
        }

        public void delete(Guid id)
        {
            //var model = getById(id);
            //db.GetTable<ProductImageEntity>().DeleteOnSubmit(model);
            //db.SubmitChanges();
            dm.delete(id);
        }

        public void update(ProductImageEntity productImage)
        {
            db = new DataBaseConnect().DataBase;
            var old = getById(productImage.Id);
            old.CopyPropyties(productImage);
            db.SubmitChanges();
        }

        public void save(ProductImageEntity productImage)
        {
            //var model = getById(id);
            //db.GetTable<ProductImageEntity>().InsertOnSubmit(model);
            //db.SubmitChanges();
            dm.save(productImage);
        }

       
    }
}
